<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title>商品后台管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <link rel="stylesheet" href="./css/all.css">
    <link rel="stylesheet" href="./css/bootstrap.css">
    <link rel="stylesheet" href="./css/course_category.css">
    <style>
        .text-center-content {
            color: #58595a;
            text-align: center;
        }
    </style>

</head>

<body>
    <div id="app">

        <nav class="navbar">
            <div class="container" style="height: 80px;background: #58a3f9">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <a class="navbar-brand" href="#" style="">
                        <img src="image/easy-pay.png">
                    </a>
                </div>
                <ul class="nav navbar-nav navbar-right" style="margin-top: 30px">
                    <li><a href="#"><span class="inner">首页</span></a></li>
                    <li>
                        <a href="#">
                            <span class="inner">商品管理</span></a>
                    </li>
                    <li>
                        <a href="#">
                            <span class="inner">购物车管理</span>
                        </a>
                    </li>

                    <li>
                        <a href="#">
                            <span class="inner">用户管理</span></a>
                    </li>
                </ul>

            </div>
        </nav>
        <div style="min-height: 400px">
            <div class="container">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4>商品管理-商品列表</h4>
                    </div>
                    <div class="panel-body">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th style="width: 15%" class="text-center">商品编号</th>
                                    <th style="width: 65%" class="text-center">商品标题</th>
                                    <th style="width: 20%" class="text-center">操作</th>
                                </tr>
                            </thead>
                            <tbody id="mytbody">
                                <!--此处为商品列表内容-->
                                <tr v-for="(item,value) in data" :key="value">
                                    <th style="width: 15%" class="text-center-content">{{item.id}}</th>
                                    <th style="width: 65%" class="text-center-content">{{item.title}}</th>
                                    <th style="width: 20%" class="text-center-content">
                                        <span>
                                            <button class="btn btn-primary">详细</button>

                                        </span>
                                        <span>
                                            <button class="btn btn-primary">编辑</button>

                                        </span>
                                        <span>
                                            <button class="btn btn-primary" @click="deletGood(item.id)">删除</button>

                                        </span>
                                    </th>
                                </tr>

                            </tbody>
                        </table>
                        <div>
                            <button class="btn btn-primary">添加商品</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <footer>
            <div class="container">
                <p class="text-center">易购集团</p>
                <p class="text-center">Copyright 2019</p>
            </div>
        </footer>
    </div>

</body>

</html>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="./js/axios.min.js"></script>
<script>
    //这里ajax实现和后台交互
    new Vue({
        el: "#app",
        data: {
            data: undefined
        },
        methods: {
            deletGood(id) {
                console.log(id);
                var that = this;
                axios.post('http://127.0.0.1:8080//h7/goods/deleteGoods', {
                    id
                })
                    .then(function (res) {
                        console.log(res);
                        that.onlist()
                    })
                    .catch(function (err) {
                        console.log(err);
                    });
            },
            onlist() {
            var that = this;
            axios.post('http://127.0.0.1:8080/h3/goods/list')
                .then(function (res) {
                    console.log(res);
                    if (res.data.list != null && res.data.success == true) {
                        that.data = res.data.list
                        console.log(that.data);

                    }

                })
                .catch(function (err) {
                    console.log(err);
                });
        }

        },
        created() {
            this.onlist()
        }
    })


</script>